<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div class="app">
        <p>过滤小写成大写</p>
        <h1>{{msg | upper}}</h1>
        <p>过滤大写成小写</p>
        <h1>{{big_msg | lower}}</h1>
        <p>过滤事件戳成电脑格式</p>
        <h1>{{date | date}}</h1>
        <p>将电话号码过滤成常用格式</p>
        <h1>{{tep | tepformat}}</h1>

    </div>
    <script src="../vue.js"></script>
    <script>
        //全局过滤器，将小写过滤成大写
        Vue.filter("upper", (value) => {
            if (!value) return ""
            return value.toUpperCase()
        })

        //全局过滤器，将大写过滤成小写
        Vue.filter("lower", (value) => {
            if (!value) return ""
            return value.toLowerCase()
        })

        //过滤事件戳成电脑格式
        Vue.filter("date", (value) => {
            if (!value) return ""
            let time = new Date(value)
            let year = time.getFullYear()
            let month = time.getMonth() + 1
            let day = time.getDate()
            let hour = time.getHours()
            let min = time.getMinutes()
            let second = time.getSeconds()
            return `${year}-${month}-${day} ${hour}:${min}:${second}`
        })

        //将电话号码过滤成常用格式
        Vue.filter("tepformat", (value, str) => {
            if (!value) return ""
            str = str || '-'
            value = value.toString().split('')
            value.splice(3, 0, str)
            value.splice(8, 0, str)
            return value.join("")


        })

        let vm = new Vue({
            data: {
                msg: "nishishagua",
                big_msg: "CARZY",
                date: new Date(),
                tep: 18671643106,
            },
            mounted() {
                setInterval(function() {
                    vm.date = new Date()
                }, 1000)
            }

        }).$mount(".app")
    </script>
</body>

</html>